package org.easymis.crm.modules.biplatform.controller;

import java.util.HashMap;
import java.util.List;

import org.easymis.commons.web.utils.Page;
import org.easymis.commons.web.utils.R;
import org.easymis.crm.config.SystemConstant;
import org.easymis.crm.modules.biplatform.entitys.mybatis.dto.Dashboard;
import org.easymis.crm.modules.biplatform.service.DashboardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;


@Api(tags = "数据看板")
@Controller
public class DashboardController {
	@Autowired
	private DashboardService service;

	@ApiOperation(value = "数据看板列表页面", notes = "", produces = MediaType.TEXT_HTML_VALUE)
	@RequestMapping(value = { "/dashboards" }, method = { RequestMethod.GET, RequestMethod.POST })
	public String dashboards(ModelMap map) {

		return "/biplatform/dashboard/index";
	}
	
	@ApiOperation(value = "数据看板列表页面", notes = "", produces = MediaType.TEXT_HTML_VALUE)
	@RequestMapping(value = { "/dashboard/forward/list.html" }, method = { RequestMethod.GET, RequestMethod.POST })
	public String forwardList(ModelMap map, Page page) {
		return "/biplatform/dashboard/list";
	}
	@ApiOperation(value = "数据看板列表JSON数据", notes = "", produces = MediaType.TEXT_HTML_VALUE)
	@RequestMapping(value = { "/dashboard/list.json" }, method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public R forwardListJson(ModelMap map, Page page) {
		PageHelper.startPage(page.getCurPage(), page.getPageSize());
		List<Dashboard> dashboardList = service.getList(new HashMap<String, Object>());
		PageInfo<Dashboard> p = new PageInfo<Dashboard>(dashboardList);
		return new R().put("page", p);
	}
	@ApiOperation(value = "跳转添加业务切片", notes = "", produces = MediaType.TEXT_HTML_VALUE)
	@RequestMapping(value = { "/dashboard/forward/add.html" }, method = { RequestMethod.GET, RequestMethod.POST })
	public String forwardAdd(ModelMap map, Page page) {
		return "/biplatform/dashboard/add";
	}
	@ApiOperation(value = "跳转添加业务切片", notes = "", produces = MediaType.TEXT_HTML_VALUE)
	@RequestMapping(value = { "/dashboard/save.do" }, method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public R save(ModelMap map, Dashboard bean) {
		service.save(bean);
		return new R().ok();
	}
	@ApiOperation(value = "数据看板列表", notes = "", produces = MediaType.TEXT_HTML_VALUE)
	@RequestMapping(value = { "/api/dashboards" }, method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public R apiDashboard(ModelMap map, Page page) {
		PageHelper.startPage(page.getCurPage(), page.getPageSize());
		List<Dashboard> dashboardList = service.getList(new HashMap<String, Object>());
		PageInfo<Dashboard> p = new PageInfo<Dashboard>(dashboardList);
		return new R().put("page", p);
	}

	@ApiOperation(value = "数据看板详情", notes = "", produces = MediaType.TEXT_HTML_VALUE)
	@RequestMapping(value = { "/dashboard/{dashboardId}.json" }, method = { RequestMethod.GET, RequestMethod.POST })
	public R view(@PathVariable("dashboardId") String dashboardId, ModelMap map) {
		return new R().ok();
	}

	@ApiOperation(value = "数据看板详情页面", notes = "", produces = MediaType.TEXT_HTML_VALUE)
	@RequestMapping(value = { "/dashboard/delete/{dashboardId}" }, method = { RequestMethod.GET, RequestMethod.POST })
	public R delete(@PathVariable("dashboardId") String dashboardId, ModelMap map) {
		return new R().ok();
	}

	@ApiOperation(value = "公开数据看板详情页面", notes = "", produces = MediaType.TEXT_HTML_VALUE)
	@RequestMapping(value = { "/public/dashboard/{dashboardId}.html" }, method = { RequestMethod.GET, RequestMethod.POST })
	public String publicDashboard(@PathVariable("dashboardId") String dashboardId, ModelMap map) {

		return "/biplatform/dashboard/view";
	}
	
	@ApiOperation(value = "公开数据看板详情数据", notes = "", produces = MediaType.TEXT_HTML_VALUE)
	@RequestMapping(value = { "/public/dashboard/{dashboardId}.json" }, method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public R publicDashboardJson(@PathVariable("dashboardId") String dashboardId, ModelMap map) {
		map.put("icp", SystemConstant.getICP());
		map.put("systemname", SystemConstant.getSystemName());
		map.put("systemdomain", SystemConstant.getSystemdomain());
		return new R().put("dashboard", service.findById(dashboardId));
	}
}
